package ebj.common.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.TypeVariable;

import ebj.common.utils.Utils;

/**
 * 反射实例9：通过反射调用其他类中的方法
 * @author zhouxiangyong
 * @version $Id$
 */
public class ReflectClient9 {
	public static void main(String[] args) {
		String clazzName = Utils.getProperty("Person");
		Class<?> clazz = null;
		try {
			clazz = Class.forName(clazzName);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			Method[] methods = clazz.getDeclaredMethods();
			for (Method method : methods) {
				System.out.println(method);
				Class<?>[] parmsTypes = method.getParameterTypes();
				System.out.println(Modifier.toString(method.getModifiers()));
				if (parmsTypes.length == 0 && "private".equals(Modifier.toString(method.getModifiers()))) {
					method.setAccessible(true);
					method.invoke(clazz.newInstance());
				}
				for (Class<?> class1 : parmsTypes) {
					System.out.println(class1);
				}
				System.out.println(Modifier.toString(method.getModifiers()));
				System.out.println("******************");
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
